home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK2.toast / Development Kits (Disc 2) / ScriptX / Documentation / Code Examples from Docs / toolguid / dtksampl / mystrans.sx < prev   
Encoding:
Text File  |  1996-05-21  |  6.3 KB  |  217 lines  |  [TEXT/ttxt]

  1. -- Filename:
  2. --       myStrans.sx
  3.  
  4. -- Purpose:
  5. --      This file defines a score translator that
  6. --    prints information about a score  in a Director file
  7. --    to an output file
  8.  
  9.  
  10. -- Specialized Classes:
  11.  
  12. --     The main specialized class is ScoreToInfoTranslator
  13. --    which defines the translateFrame method to translate
  14. --    frames in a Director score when importing into ScriptX.
  15.  
  16.  
  17. -- Instructions to User:
  18. --      Don't load this file directly.
  19. --    Instead, load converter.sx, which loads this file.
  20. --     converter.sx creates an instance of ScoreToInfoTranslator
  21. --     and  uses it to import a score from a Director file
  22.  
  23. -- Author:
  24. --      Jocelyn Becker
  25.  
  26.  
  27.  
  28.  
  29.  
  30. in Module myModule
  31.  
  32. -- Create the new class of Score Translator
  33. class ScoreToInfoTranslator (DTKScoreTranslator)
  34. end
  35.  
  36.  
  37. method prepareToTranslateScore self {class ScoreToInfoTranslator} -> 
  38. (
  39.     print "\nI am preparing to translate the score. Silence please.\n" 
  40. )
  41.  
  42.  
  43.  
  44. method translateFrame self {class ScoreToInfoTranslator} \
  45.             prevFrame currentFrame changedArray -> 
  46. (
  47.     local framenum := currentFrame.absoluteFrameNumber
  48.  
  49.     -- Print the frame number
  50.     format self.outputstream "\n\n\nProcessing frame number %* \n" \            
  51.         framenum @unadorned
  52.  
  53.     -- Translate data about the frame
  54.     translateTempoDataToText self prevFrame currentFrame
  55.     translateSoundDataToText self prevFrame currentFrame
  56.     translateSpriteDataToText self prevFrame currentFrame changedArray
  57. )
  58.  
  59. --------------------------------------------
  60. -- USER-DEFINED METHODS TO DO TRANSLATING
  61. --------------------------------------------
  62.  
  63.  
  64. ---------------------
  65. -- Translate Tempo --
  66. ---------------------
  67.  
  68. method translateTempoDataToText self {class ScoreToInfoTranslator}\
  69.         prevFrame currentFrame ->
  70. (
  71.     local currentTempo := currentFrame.tempochannel
  72.     
  73.     -- Print a message to the output stream that says whether the 
  74.     -- the tempo has changed since the previous frame, and 
  75.     -- what the current tempo is.
  76.     if (currentFrame.tempoChannel.tempo <> prevFrame.tempoChannel.tempo) 
  77.     then
  78.         format self.outputstream "\nThe tempo has changed to %* \n" \
  79.             currentTempo.tempo @unadorned
  80.     else 
  81.         format self.outputstream "\nThe tempo is still %* \n" \
  82.             currentTempo.tempo @unadorned
  83.     
  84.     -- Lets see if we need to wait for any sounds.
  85.     -- The value of the DTKTempoChannel's waitForSound instance variable is:
  86.     -- 0 (don't wait for any sound), 
  87.     -- 1 (wait for the sound in channel 1) or
  88.     -- 2 (wait for the sound in channel 2)
  89.     if (currentFrame.tempoChannel.waitForSound <> 0) do
  90.         format self.outputstream "We need to wait for the sound in channel %* to finish \n" \
  91.             currentFrame.tempoChannel.waitForSound @unadorned
  92.  
  93. )
  94.  
  95.  
  96. ---------------------
  97. -- Translate Sound --
  98. ---------------------
  99.  
  100. method translateSoundDataToText self {class ScoreToInfoTranslator} \
  101.         prevFrame currentFrame ->
  102. (
  103.     -- A DTKScoreFrame object has a soundChannels iv that contains
  104.     -- an array of two DTKSoundChannel objects, one for each sound channel
  105.  
  106.     -- For each sound channel, find which position the sound playing 
  107.     -- in that channel occupies in the cast list.
  108.     -- Print sutiable messsages to the output stream.
  109.     for i := 1 to 2 do (
  110.         local oldIndex := prevFrame.soundChannels[i].castIndex
  111.         local newIndex := currentFrame.soundChannels[i].castIndex
  112.  
  113.         -- If no sound is playing in this channel, castIndex will be 0
  114.         if (newIndex <> 0)  
  115.         then 
  116.             format self.outputstream "Sound channel %1 is playing sound %2.\n" \
  117.                 #(i, self.castlist[newIndex].mediastream) \
  118.                 #(@unadorned, @unadorned)
  119.         else 
  120.             format self.outputstream "Sound channel %* is currently silent.\n" \
  121.                 i @unadorned
  122.  
  123.         if newIndex <> oldIndex 
  124.         then 
  125.             format self.outputstream "This is a change from the previous frame. \n" \
  126.                 1 @unadorned
  127.         else 
  128.             format self.outputstream "This is the same as for the previous frame. \n" \
  129.                 1 @unadorned
  130.  
  131.         -- close loop
  132.     )
  133. )
  134.  
  135.  
  136. -----------------------
  137. -- Translate Sprites --
  138. -----------------------
  139.  
  140. method translateSpriteDataToText self {class ScoreToInfoTranslator} \
  141.         prevFrame currentFrame changedArray ->
  142.  
  143. (
  144.     -- Get the cast list.
  145.     theCastList := self.castlist
  146.  
  147.     -- For each sprite channel: 
  148.     for i := 1 to 48 do 
  149.     (        
  150.         -- Find which sprite channel we are currently focusing on.
  151.         local theSpriteChannel := currentFrame.spriteChannels[i]
  152.         local thePrevSpriteChannel := prevFrame.spriteChannels[i]
  153.     
  154.         -- Find which position the sprite that appears in 
  155.         -- that channel occupies in the cast list.
  156.         local spritePosition := theSpriteChannel.castIndex
  157.         local prevSpritePosition := thePrevSpriteChannel.castIndex
  158.         
  159.         -- Find the actual cast member object for the sprite in the channel
  160.         thisCast := theCastList[spritePosition]
  161.         prevCast := theCastList[prevSpritePosition]
  162.  
  163.         -- Print suitable messages to the output stream.
  164.         if thisCast <> empty do
  165.         (
  166.             format self.outputstream "\n The castmember in channel %1 is %2. \n\
  167.             Its name is %10. \n.
  168.             It is at position %3 in the cast list. \n\
  169.             This cast member is a %4. \n \
  170.             Its x coordinate is %5. \n \
  171.             Its y coordinate is %6.\n \
  172.             Its inkmode is %7. \n \
  173.             It is %8 high and %9 wide. \n\n" \
  174.                 #(i, thisCast, spritePosition, (getClass thisCast), \
  175.                 theSpriteChannel.x,      theSpriteChannel.y, \
  176.                 thespriteChannel.ink, \
  177.                 theSpriteChannel.height, theSpriteChannel.width, thisCast.name) \
  178.                 #(@unadorned, @unadorned, @unadorned, @unadorned, @unadorned, 
  179.                 @unadorned, @unadorned, @unadorned, @unadorned)
  180.                 
  181.         
  182.  
  183.             if changedArray[i] == false
  184.             then 
  185.                 print "No change in this sprite channel." self.outputstream 
  186.             else    
  187.             (
  188.                 -- Compare the ink mode of the current and previous frames
  189.                 if (thePrevSpriteChannel.ink <> theSpriteChannel.ink) 
  190.                 do
  191.                     print "The ink mode has changed since the previous channel.\n"     \
  192.                         self.outputstream
  193.         
  194.                 -- Comparing the state of the sprite in the 
  195.                 -- current and previous frames
  196.  
  197.                 if (thisCast <> prevCast)  
  198.                 do
  199.                     print "The sprite has changed." self.outputstream
  200.             
  201.                 if (thePrevSpriteChannel.x <> theSpriteChannel.x) or
  202.                     (thePrevSpriteChannel.y <> theSpriteChannel.y) 
  203.                 do
  204.                     print "The sprite has changed position." self.outputstream
  205.         
  206.         
  207.                 if (thePrevSpriteChannel.width <> theSpriteChannel.width) or
  208.                     (thePrevSpriteChannel.height <> theSpriteChannel.height) 
  209.                 do
  210.                     print "The sprite has changed size." self.outputstream
  211.             ) -- closes if changedArray[i] == false
  212.         
  213.         ) -- closes if thisCast <> empty else
  214.  
  215.     ) -- closes for i := 1 to 48 do
  216. ) -- closes method
  217.